package com.ds.lens.flink.monitor.common;

import com.ds.lens.flink.monitor.MonitorJobContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.streaming.util.serialization.KeyedSerializationSchema;

import java.nio.charset.StandardCharsets;

@Slf4j
public class CommonSerializationSchema<T> implements KeyedSerializationSchema<T> {

    @Override
    public byte[] serializeKey(T element) {
        return null;
    }

    @Override
    public byte[] serializeValue(T element) {
        try {
            return MonitorJobContext.getInstance().getGson().toJson(element).getBytes(StandardCharsets.UTF_8);
        } catch (Exception e) {
            log.error("Failed to parse JSON", e);
            return new byte[0];
        }
    }

    @Override
    public String getTargetTopic(T element) {
        return null;
    }
}
